import { EntitySchema, Ref } from '@mikro-orm/core';
import { JobProjectJobs } from './JobProjectJobs';
import { JobTasks } from './JobTasks';
import { Users } from './Users';

export class OrderJobEnrolls {
  id!: string;
  createdAt?: Date;
  updatedAt?: Date;
  enroller?: Ref<Users>;
  agent?: Ref<Users>;
  jobTask?: Ref<JobTasks>;
  expectedJob?: Ref<JobProjectJobs>;
  rejectedAt?: Date;
  kickoutAt?: Date;
  assignedJobAt?: Date;
  isLeader: boolean = false;
  signUpAt?: Date;
  signDownAt?: Date;
  verifiedAt?: Date;
  giveSalaryAt?: Date;
  salary?: string;
  salaryGiver?: Ref<Users>;
  faceIdentifyAt?: Date;
  name?: string;
  phoneNumber?: string;
  idNumber?: string;
  bankAddress?: string;
  bankAccount?: string;
  state?: string;
  recruiter?: string;
  phone?: string;
  commission?: string;
  commissionUnit?: string;
  deposit?: string;
  price?: string;
  num?: string;
  age?: string;
  sex?: string;
  startTime?: string;
  endTime?: string;
}

export const OrderJobEnrollsSchema = new EntitySchema({
  class: OrderJobEnrolls,
  properties: {
    id: { primary: true, type: 'string', columnType: 'bigint' },
    createdAt: { type: 'Date', length: 0, nullable: true },
    updatedAt: { type: 'Date', length: 0, nullable: true },
    enroller: {
      reference: 'm:1',
      entity: () => Users,
      ref: true,
      onUpdateIntegrity: 'cascade',
      onDelete: 'cascade',
      nullable: true,
      index: 'enroller_user_foreign_key',
    },
    agent: {
      reference: 'm:1',
      entity: () => Users,
      ref: true,
      onUpdateIntegrity: 'cascade',
      onDelete: 'cascade',
      nullable: true,
      index: 'agent_foreign_key',
    },
    jobTask: {
      reference: 'm:1',
      entity: () => JobTasks,
      ref: true,
      onUpdateIntegrity: 'cascade',
      onDelete: 'cascade',
      nullable: true,
      index: 'job_tasks_foreign_key',
    },
    expectedJob: {
      reference: 'm:1',
      entity: () => JobProjectJobs,
      ref: true,
      onUpdateIntegrity: 'cascade',
      onDelete: 'cascade',
      nullable: true,
      index: 'expected_job_foreign_key',
    },
    rejectedAt: { type: 'Date', length: 0, nullable: true },
    kickoutAt: { type: 'Date', length: 0, nullable: true },
    assignedJobAt: { type: 'Date', length: 0, nullable: true },
    isLeader: { type: 'boolean', default: false },
    signUpAt: { type: 'Date', length: 0, nullable: true },
    signDownAt: { type: 'Date', length: 0, nullable: true },
    verifiedAt: { type: 'Date', length: 0, nullable: true },
    giveSalaryAt: { type: 'Date', length: 0, nullable: true },
    salary: { type: 'string', length: 255, nullable: true },
    salaryGiver: {
      reference: 'm:1',
      entity: () => Users,
      ref: true,
      onUpdateIntegrity: 'cascade',
      onDelete: 'cascade',
      nullable: true,
      index: 'giver_users_enrolls',
    },
    faceIdentifyAt: { type: 'Date', length: 0, nullable: true },
    name: { type: 'string', length: 255, nullable: true },
    phoneNumber: { type: 'string', length: 255, nullable: true },
    idNumber: { type: 'string', length: 255, nullable: true },
    bankAddress: { type: 'string', length: 255, nullable: true },
    bankAccount: { type: 'string', length: 255, nullable: true },
    state: { type: 'string', length: 255, nullable: true },
    recruiter: { type: 'string', length: 255, nullable: true },
    phone: { type: 'string', length: 255, nullable: true },
    commission: { type: 'string', length: 255, nullable: true },
    commissionUnit: { type: 'string', length: 255, nullable: true },
    deposit: { type: 'string', length: 255, nullable: true },
    price: { type: 'string', length: 255, nullable: true },
    num: { type: 'string', length: 255, nullable: true },
    age: { type: 'string', length: 255, nullable: true },
    sex: { type: 'string', length: 255, nullable: true },
    startTime: { type: 'string', length: 255, nullable: true },
    endTime: { type: 'string', length: 255, nullable: true },
  },
});
